package com.RedRiver.hospitalsystem.record_service.app.controller;


import cn.hutool.core.bean.BeanUtil;
import com.RedRiver.hospitalsystem.record_service.client.PapersClient;
import com.RedRiver.hospitalsystem.record_service.client.result.GetpapersResult;
import com.RedRiver.hospitalsystem.record_service.info.Getpapers;
import com.RedRiver.hospitalsystem.record_service.service.PapersService;
import com.RedRiver.hospitalsystem.result.Result;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/papers")
@Api(tags = "证件相关")
public class PapersController implements PapersClient {

    @Resource
    private PapersService papersService;

    @Override
    @ApiOperation("添加证件类型")
    public Result<?> createPaper(@ApiParam("请输入证件类型") @RequestParam("cardType") String cardType) {
       return papersService.addPaper(cardType);
    }

    @ApiOperation("删除证件类型")
    @Override
    public Result<?> downPaper(@ApiParam("请输入证件id") @RequestParam("cardType")Integer id) {
     return papersService.deletePaper(id);
    }


    @Override
    @ApiOperation("查询所有证件类型")
    public Result<List<GetpapersResult>> paperList() {
        List<Getpapers> papers=papersService.getallPapers();
        List<GetpapersResult> allpapers = BeanUtil.copyToList(papers, GetpapersResult.class);
        return Result.getInstanceList(GetpapersResult.class).setData(allpapers).setMsg("查询成功");
    }

}

